package com.lovo.Atm;

import javax.swing.*;

import com.lovo.Util;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * 菜单里有四个按钮图片 存 取 查  退出
 */
public class Menu extends JPanel implements ActionListener {
    private Icon getBtn = Util.iconImg("/images/buttonGet.jpg");
    private Icon saveBtn = Util.iconImg("/images/buttonSave.jpg");
    private Icon findBtn = Util.iconImg("/images/buttonFind.jpg");
    private Icon backBtn = Util.iconImg("/images/buttonOff.jpg");
    private Icon mod = Util.iconImg("/images/buttonModify.jpg");

    private Home frame;
    private JButton saveImg;
    private JButton getImg;
    private JButton findImg;
    private JButton backImg;
    private JButton transfer;
    private JButton modImg;

    public Menu(Home frame) {
        this.frame = frame;
        this.setLayout(null);
        this.setOpaque(false);

        //存款按钮
        saveImg = new JButton(saveBtn);
        saveImg.setBounds(280, 200, 140, 50);
        this.add(saveImg);
        saveImg.addActionListener(this);

        //取款按钮
        getImg = new JButton(getBtn);
        getImg.setBounds(450, 200, 140, 50);
        this.add(getImg);
        getImg.addActionListener(this);

        //查询按钮
        findImg = new JButton(findBtn);
        findImg.setBounds(620, 200, 140, 50);
        this.add(findImg);
        findImg.addActionListener(this);

        //转账按钮
        transfer = new JButton(" 转账 ");
        transfer.setBounds(280, 300, 140, 50);
        transfer.setFont(new Font("宋体", Font.BOLD, 20));
        this.add(transfer);
        transfer.addActionListener(this);


        //改密按钮
        modImg = new JButton(mod);
        modImg.setBounds(450, 300, 140, 50);
        this.add(modImg);
        modImg.addActionListener(this);

        //返回登录界面
        backImg = new JButton(backBtn);
        backImg.setBounds(620, 300, 140, 50);
        this.add(backImg);
        backImg.addActionListener(this);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == backImg) {
            frame.switchPanel("land");
        }
        if (e.getSource() == saveImg) {
            frame.switchPanel("save");
        }
        if (e.getSource() == findImg) {
            frame.switchPanel("find");
        }
        if (e.getSource() == getImg) {
            frame.switchPanel("get");
        }
        if (e.getSource() == transfer) {
            frame.switchPanel("transfer");
        }
        if (e.getSource() == modImg){
            frame.switchPanel("mod");
        }
    }
}
